
package system.base;

import framework.core.*;
import system.data.*;
/*
	Author    :Jackey
	CreateTime:2008-02-27 11:04:38
*/
public class TableSequenceSrv extends IHandler
{

	public TableSequenceSrv() 
	{
		super();
	}
	private void deleteTableSequence(DBConnection con,SrvContext context) throws Exception
	{
		String[] ids = context.getParameterValues("ids");
		TableSequence obj = null;
		for(int i=0;i<ids.length;i++)
		{
			obj = TableSequence.fetch(con,ids[i]);
			if(obj!=null) obj.delete(con);
		}
	}
	private void saveTableSequence(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String id = context.getString("Id",null);
		TableSequence obj;
		if((id==null)||(id.equals("")))   //add
		{
			obj = TableSequence.fetch();
    	}
    	else                     //update
    	{
    		obj = TableSequence.fetch(con,id);
    	}
		TableSequencePageData data = (TableSequencePageData)PageData.fromForm(context,TableSequencePageData.class);
		context.setValue("TableSequencePageData",data);
		obj.fill(data);
		obj.save(con);
	}
	private void listTableSequence(DBConnection con,SrvContext context,String path) throws Exception
	{
		TableSequenceSearchEvent event = (TableSequenceSearchEvent)SearchEvent.fromForm(context,TableSequenceSearchEvent.class);
		context.setSessionValue("TableSequenceSearchEvent",event);
		context.setNextUrl(path+"TableSequenceList.jsp");
	}
	private void backTableSequence(DBConnection con,SrvContext context,String path) throws Exception
	{
		context.setNextUrl(path+"TableSequenceList.jsp");
	}
	
	public void doAction(DBConnection con,SrvContext context,ILoginContext loginContext) throws Exception
	{
		String action_code = context.getActionCode();
		String path = "/system/base/";
		
		if(action_code.equalsIgnoreCase("listTableSequence"))
		{
			listTableSequence(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("viewTableSequence"))
		{
			String id = context.getString("Id",null);
			TableSequence obj = TableSequence.fetch(con,id);
			context.setValue("TableSequence",obj);
			context.setNextUrl(path+"TableSequenceView.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("deleteTableSequence"))
		{
			context.setErrorUrl(path+"TableSequenceList.jsp");
			deleteTableSequence(con,context);
			backTableSequence(con,context,path);
			return;
		}
			
		if(action_code.equalsIgnoreCase("toAddTableSequence"))
		{
			TableSequence obj = TableSequence.fetch();
			TableSequencePageData data = (TableSequencePageData)PageData.fromTable(obj,TableSequencePageData.class);
			context.setValue("TableSequencePageData",data);
			context.setNextUrl(path+"TableSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toUpdateTableSequence"))
		{
			String id = context.getString("Id",null);
			TableSequence obj = TableSequence.fetch(con,id);
			TableSequencePageData data = (TableSequencePageData)PageData.fromTable(obj,TableSequencePageData.class);
			context.setValue("TableSequencePageData",data);
			context.setNextUrl(path+"TableSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("toCopyTableSequence"))
		{
			String id = context.getString("Id",null);
			TableSequence obj = TableSequence.copy(TableSequence.fetch(con,id));
			TableSequencePageData data = (TableSequencePageData)PageData.fromTable(obj,TableSequencePageData.class);
			context.setValue("TableSequencePageData",data);
			context.setNextUrl(path+"TableSequenceEdit.jsp");
			return;
		}
		if(action_code.equalsIgnoreCase("saveTableSequence"))
		{
			context.setErrorUrl(path+"TableSequenceEdit.jsp");
			saveTableSequence(con,context,loginContext);
			backTableSequence(con,context,path);
			return;
		}
		if(action_code.equalsIgnoreCase("saveAndNewTableSequence"))
		{
			context.setErrorUrl(path+"TableSequenceEdit.jsp");
			saveTableSequence(con,context,loginContext);
			TableSequence obj = TableSequence.fetch();
			TableSequencePageData data = (TableSequencePageData)PageData.fromTable(obj,TableSequencePageData.class);
			context.setValue("TableSequencePageData",data);
			context.setNextUrl(path+"TableSequenceEdit.jsp");			
			return;
		}
		if(action_code.equalsIgnoreCase("backListTableSequence"))
		{
			backTableSequence(con,context,path);
			return;
		}
		
		//add by Jackey start

		//add by Jackey end

		Logger.throwException("TableSequenceSrv","unknown action_code="+action_code);
	}
}
